var t = getApp();

Page({
    data: {
        invoiceType: 1,
        loading: !1,
        finshed: !1,
        page: 1,
        total: 0,
        invoiceList: [],
        orderList: [],
        bearerList: [],
        sinvoice: {}
    },
    onLoad: function(t) {
        void 0 !== t.type && this.setData({
            invoiceType: 1 * t.type
        });
    },
    onShow: function() {
        this._initData(), this.getListData();
    },
    changeTab: function(t) {
        t.detail.name != this.data.invoiceType && (this.setData({
            invoiceType: t.detail.name
        }), this._initData(), this.getListData());
    },
    _initData: function() {
        this.setData({
            loading: !1,
            finshed: !1,
            page: 1,
            total: 0,
            invoiceList: [],
            orderList: [],
            bearerList: []
        });
    },
    getListData: function() {
        var a = this;
        if (this.data.finshed || this.data.loading) return !1;
        var i = "", e = {
            page: this.data.page
        };
        "-1" == this.data.invoiceType ? i = t.getNetAddresss("plugin.invoice.frontend.rise.get-list") : "3" == this.data.invoiceType ? i = t.getNetAddresss("plugin.invoice.frontend.index.not-invoice") : (i = t.getNetAddresss("plugin.invoice.frontend.index.index"), 
        e.status = this.data.invoiceType), this.setData({
            loading: !0
        }), t._getNetWork({
            url: i,
            data: e,
            success: function(i) {
                var e = i.data;
                if (1 != e.result) return t.tips(e.msg);
                var s = e.data;
                (a.data.page >= s.last_page || s.data.length < s.pre_page) && a.setData({
                    finshed: !0
                }), a.setChildData(s), a.setData({
                    page: a.data.page + 1,
                    total: s.total
                });
            },
            complete: function() {
                a.setData({
                    loading: !1
                });
            }
        });
    },
    setChildData: function(t) {
        var a = this.data.invoiceType;
        "-1" == a ? this.setData({
            bearerList: this.data.bearerList.concat(t.data)
        }) : "3" == a ? (t.data.forEach(function(t) {
            t.button_models = [ {
                name: "申请开票",
                value: "apply_invoice",
                api: "test",
                type: ""
            } ];
        }), this.setData({
            orderList: this.data.orderList.concat(t.data),
            sinvoice: t.sinvoice
        })) : this.setData({
            invoiceList: this.data.invoiceList.concat(t.data)
        });
    },
    refreshComponent: function() {
        this.setData({
            loading: !1,
            finshed: !1,
            page: 1,
            total: 0,
            invoiceList: [],
            orderList: [],
            bearerList: []
        }), this.getListData();
    },
    onReachBottom: function() {
        this.getListData();
    },
    onShareAppMessage: function() {}
});